package com.GZHU.controller.query_info;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
public class Query_use_info {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @GetMapping("/use")
    public String query_use_info(@RequestParam("model_id") String model_id,
                                 @RequestParam("time") String time,
                                 Model model){
        String sql= String.format("SELECT * FROM use_info WHERE model_id='%s' AND start_time='%s'", model_id,time);
        List res0=jdbcTemplate.queryForList(sql);
        Map res=(Map) res0.get(0);
        model.addAttribute("use_id",res.get("use_id"));
        model.addAttribute("model_id",res.get("model_id"));
        model.addAttribute("consumer_id",res.get("consumer_id"));
        model.addAttribute("start_time",res.get("start_time"));
        model.addAttribute("end_time",res.get("end_time"));
        return "use_info";
    }
}
